home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / Rexx / PrintTable.rexx < prev    next >
OS/2 REXX Batch file  |  2000-05-08  |  8KB  |  278 lines

  1. /*RX
  2.     $RCSFile: $
  3.     $Revision: 3.1 $
  4.     $Date: 1994/03/23 15:52:36 $
  5.  
  6.     This program was created to satisfy the needs of some swiss users.
  7.     They want to have the table output in a slightly another fashion
  8.     than it is originally. Besides that it is a decent example of
  9.     using Chaos via the ARexx port.
  10.  
  11.     Usage: PrintTable [tabmode [plrmode [linesperpage]]]
  12.  
  13.     tabmode and plrmode are the tables sorting mode and the player mode
  14.     as documented in the ARexx call 'Table'.
  15.     linesperpage is the number of lines to be printed before a page break.
  16.     0 suppresses page breaks. (This is the default.)
  17.  
  18.  
  19.     The original table output looks like this:
  20.  
  21.     Place Points Buchholz Name
  22.  
  23.     This should be changed to look like this:
  24.  
  25.     Place Name            Chess club            Points Buchholz
  26.  
  27.     What we need to do is:
  28.  
  29.     1) Let Chaos print the table into one file.
  30.     2) Let Chaos print the list of players into another file.
  31.     3) Write the new table to stdout. (We can use redirection, if this
  32.        should go to another file or the printer.)
  33.  
  34.     Note, that this can only be used, when Chaos is able to accept
  35.     commands, i.e. if menuitems can be selected.
  36. */
  37.  
  38. /*
  39.     Setting up global variables
  40. */
  41. TableFileName        = "t:PrintTable.table";
  42. PlayerListFileName  = "t:PrintTable.playerlist";
  43. DefaultTableMode    = "0";
  44. DefaultPlayerMode   = "0";
  45. DefaultLinesPerPage = "0";  /*  0 means no page breaks  */
  46.  
  47.  
  48.  
  49.  
  50. /*
  51.     Parsing command line arguments.
  52. */
  53. PARSE ARG TableMode PlayerMode LinesPerPage
  54. IF  TableMode == "?"  THEN DO
  55.     SAY("Usage: PrintTable [tabmode [plrmode [linesperpage]]]");
  56.     SAY("");
  57.     SAY("Uses Chaos to create a table and prints it to stdout in a slightly");
  58.     SAY("different manner. 'Printtable >prt: [args]' prints to the printer.");
  59.     SAY("Note, that Chaos must be running, be ready to accept commands and");
  60.     SAY("must the right tournament must be loaded already.");
  61.     SAY("");
  62.     SAY("Arguments are:");
  63.     SAY("tabmode = the tables sorting mode: 0 = simple (Default), 1 = ");
  64.     SAY("          Buchholz, 2 = extended Buchholz, 3 = Sonneborn-Berger");
  65.     SAY("plrmode = which players to include into the table:");
  66.     SAY("          0 = all (Default), 1 = seniors, 2 = juniors, 3 = women,");
  67.     SAY("          4-8 = juniors A-E");
  68.     SAY("linesperpage = number of lines to print on one page. 0 suppresses");
  69.     SAY("               pagebreaks (Default).");
  70.     exit(0);
  71. END
  72. IF  TableMode == ""  THEN DO
  73.     TableMode = DefaultTableMode;
  74. END
  75. IF  PlayerMode == ""  THEN DO
  76.     PlayerMode = DefaultPlayerMode;
  77. END
  78. IF  LinesPerPage == ""  THEN DO
  79.     LinesPerPage = DefaultLinesPerPage;
  80. END
  81.  
  82.  
  83. /*
  84.     Let Chaos write the current table.
  85. */
  86. ADDRESS "CHAOS.1"   "Table "TableFileName" TABMODE="TableMode" PLRMODE="PlayerMode
  87. IF  RC ~= 0  THEN DO
  88.     SAY("Chaos: Cannot create table. (Chaos not running, no pairings or invalid");
  89.     SAY("table mode");
  90.     EXIT(10);
  91. END;
  92.  
  93.  
  94. /*
  95.     Open the table file
  96. */
  97. IF ~OPEN(.TableFile, TableFileName, "Read") THEN DO
  98.     SAY ("Cannot open table file.");
  99.     EXIT(10)
  100. END
  101.  
  102.  
  103. /*
  104.     Read the table header.
  105. */
  106. TournamentName = READLN(.TableFile);    /*  Read the tournaments name.  */
  107. Line = READLN(.TableFile);              /*  Skip empty line.            */
  108. TitleString = ReadLn(.TableFile);       /*  Read the table title.       */
  109. Line = READLN(.TableFile);              /*  Skip empty line.            */
  110. Line = READLN(.TableFile);              /*  Read the page header.       */
  111. PlaceString = WORD(Line, 1);
  112. PointsString = WORD(Line, 2);
  113. NextString = 3;
  114. IF  TableMode ~= 0  THEN DO
  115.     BuchholzString = WORD(Line, 3);
  116.     NextString = 4;
  117. END;
  118. IF  TableMode == 2  THEN DO
  119.     ExtBuchholzString = WORD(Line, 4);
  120.     NextString = 5;
  121. END;
  122. NameString = WORD(Line, NextString);
  123. Line = READLN(.TableFile);              /*  Skip empty line.            */
  124.  
  125.  
  126. /*
  127.     Read the players.
  128. */
  129. NumPlayers = 0;
  130. DO WHILE ~EOF(.TableFile);
  131.     NumPlayers = NumPlayers + 1;
  132.     Line = READLN(.TableFile);
  133.     Players.NumPlayers.Place = WORD(Line, 1);
  134.     Players.NumPlayers.Points = WORD(Line, 2);
  135.     FirstNameChar = 13;
  136.     IF    TableMode ~= 0    THEN DO
  137.     Players.NumPlayers.Buchholz = WORD(Line, 3);
  138.     FirstNameChar = 22;
  139.     END;
  140.     IF    TableMode == 2    THEN DO
  141.     Players.NumPlayers.ExtBuchholz = WORD(Line, 4);
  142.     FirstNameChar = 32;
  143.     END;
  144.     /*
  145.     Names (and the Chessclubs) may contain blanks and hence must be
  146.     handled in a different manner.
  147.     */
  148.     Players.NumPlayers.Name = STRIP(SUBSTR(Line, FirstNameChar), 'T');
  149. END
  150.  
  151.  
  152. /*
  153.     Close the table file.
  154. */
  155. IF  ~CLOSE(.TableFile)  THEN DO
  156.     SAY("Cannot close tablefile.");
  157.     EXIT(10);
  158. END;
  159.  
  160.  
  161. /*
  162.     Let Chaos write the list of players.
  163. */
  164. ADDRESS "CHAOS.1"  "PlayerList "PlayerListFileName" short"
  165.  
  166.  
  167. /*
  168.     Open the file with the list of players.
  169. */
  170. IF ~OPEN(.PlayerListFile, PlayerListFileName, "Read") THEN DO
  171.     SAY ("Cannot open list of players.");
  172.     EXIT(10)
  173. END
  174.  
  175.  
  176. /*
  177.     Read the playerlists header.
  178. */
  179. DO  i=1  TO  4                /*  Skip the tournamentname and */
  180.     Line = READLN(.PlayerListFile);     /*  the title.                  */
  181. END
  182. Line = READLN(.PlayerListFile);         /*  Read the chessclub string.  */
  183. ChessclubString = WORD(Line, 5);
  184. Line = READLN(.PlayerListFile);         /*  Skip the empty line.        */
  185.  
  186.  
  187. /*
  188.     Scan the players to find a players chess club.
  189. */
  190. DO WHILE  ~EOF(.PlayerListFile)
  191.     Line = READLN(.PlayerListFile);
  192.     CurrentName = STRIP(SUBSTR(Line, 5, 30, ), 'T',);
  193.     DO    i=1  TO  NumPlayers
  194.     IF  CurrentName == Players.i.Name  THEN DO
  195.         Players.i.ChessClub = STRIP(SUBSTR(Line, 51,,));
  196.     END
  197.     END
  198. END
  199.  
  200.  
  201. /*
  202.     Close the file with the player list.
  203. */
  204. IF  ~CLOSE(.PlayerListFile)  THEN DO
  205.     SAY("Cannot close list of players.");
  206.     EXIT(10);
  207. END;
  208.  
  209.  
  210. /*
  211.     Finally print the new table.
  212. */
  213. IF  TableMode == 0  THEN DO
  214.     HeaderString = RIGHT(PlaceString, 5)" "LEFT(NameString, 30);
  215.     HeaderString = HeaderString" "LEFT(ChessclubString, 30);
  216.     HeaderString = HeaderString" "RIGHT(PointsString, 6);
  217. END
  218. IF  TableMode == 1  |  TableMode == 3  THEN DO
  219.     HeaderString = RIGHT(PlaceString, 5)" "LEFT(NameString, 30);
  220.     HeaderString = HeaderString" "LEFT(ChessclubString, 23);
  221.     HeaderString = HeaderString" "RIGHT(PointsString, 6);
  222.     HeaderString = HeaderString" "RIGHT(BuchholzString, 8);
  223. END
  224. IF  TableMode == 2  THEN DO
  225.     HeaderString = RIGHT(PlaceString, 5)" "LEFT(NameString, 23);
  226.     HeaderString = HeaderString" "LEFT(ChessclubString, 20);
  227.     HeaderString = HeaderString" "RIGHT(PointsString, 6);
  228.     HeaderString = HeaderString" "RIGHT(BuchholzString, 8);
  229.     HeaderString = HeaderString" "RIGHT(ExtBuchholzString, 9);
  230. END
  231.  
  232.  
  233. CurrentPageLines = -1;
  234. DO  i=1  TO  NumPlayers
  235.     IF    CurrentPageLines == -1    |  CurrentPageLines = LinesPerPage  THEN DO
  236.     SAY(TournamentName);
  237.     SAY("");
  238.     SAY(TitleString);
  239.     SAY("");
  240.     SAY(HeaderString);
  241.     SAY("");
  242.     CurrentPageLines = 8;
  243.     END
  244.     IF    TableMode == 0    THEN DO
  245.     Line = RIGHT(Players.i.Place, 5)" "LEFT(Players.i.Name, 30);
  246.     Line = Line" "LEFT(Players.i.Chessclub, 30);
  247.     Line = Line" "RIGHT(Players.i.Points, 6);
  248.     END
  249.     IF    TableMode == 1    |  TableMode == 3  THEN DO
  250.     Line = RIGHT(Players.i.Place, 5)" "LEFT(Players.i.Name, 30);
  251.     Line = Line" "LEFT(Players.i.Chessclub, 23);
  252.     Line = Line" "RIGHT(Players.i.Points, 6);
  253.     Line = Line" "RIGHT(Players.i.Buchholz, 8);
  254.     END
  255.     IF    TableMode == 2    THEN DO
  256.     Line = RIGHT(Players.i.Place, 5)" "LEFT(Players.i.Name, 23);
  257.     Line = Line" "LEFT(Players.i.Chessclub, 20);
  258.     Line = Line" "RIGHT(Players.i.Points, 6);
  259.     Line = Line" "RIGHT(Players.i.Buchholz, 8);
  260.     Line = Line" "RIGHT(Players.i.ExtBuchholz, 9);
  261.     END
  262.     SAY(Line);
  263.     CurrentPageLines = CurrentPageLines + 1;
  264.     IF    CurrentPageLines = LinesPerPage  THEN DO
  265.     SAY("");
  266.     SAY("Chaos V5.3     (C) 1993        by  Jochen Wiedmann");
  267.     WRITECH(STDOUT, "0c"x);
  268.     END;
  269. END;
  270. IF  LinesPerPage ~= 0  &  CurrentPageLines ~= LinesPerPage  THEN DO
  271.     DO    i=CurrentPageLines+1  TO  LinesPerPage
  272.     SAY("");
  273.     END;
  274.     SAY("");
  275.     SAY("Chaos V5.3     (C) 1993        by  Jochen Wiedmann");
  276.     WRITECH(STDOUT, "0c"x);
  277. END;
  278.